<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Session;

class LoginController extends Controller
{
    public function index(){
        return view('home/login.index');
    }

    public function login_do(Request $request){
    	//dd($request->all());
    	$user_name = $request->user_name;

    	$password = Hash::make($request->user_pwd);
		$password = md5($request->user_pwd.'salt');

    	$result = DB::table('users')
    	->where(
    		[
    			'user_name'=>$user_name,
    			'user_pwd'=>$password
    		]
    	)->first();

    	if($result){
            Session::put('user_name',$result->user_name);
            // $data = $request->session()->all();
            // print_r($data);die;
            return 1;
    	}
    }

    //退出登陆
    public function clear(Request $request){

        Session::flush();
        return redirect('/home/index');
    }

}
